package com.lalilu.lmedia.entity

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.lalilu.lmedia.database.Linkable
import java.util.Date

@Entity(
    tableName = "playlist",
    ignoredColumns = ["matchStr", "pinyinMatchStr", "songs"]
)
data class LPlaylist(
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "p_id")
    var _id: Long = 0,

    @ColumnInfo(name = "p_title")
    val _title: String,

    @ColumnInfo(name = "p_create_time")
    val createTime: Date = Date(),

    override var nextId: Long? = null,
) : MusicParent(), Linkable {

    override val id: String
        get() = _id.toString()

    override val name: String
        get() = _title

    override var songs: List<LSong> = emptyList()
    override fun getLinkableId(): Long = _id

    override fun setLinkableId(id: Long) {
        _id = id
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as LPlaylist

        if (_id != other._id) return false
        if (_title != other._title) return false
        if (createTime != other.createTime) return false

        return true
    }

    override fun hashCode(): Int {
        var result = _id.hashCode()
        result = 31 * result + _title.hashCode()
        result = 31 * result + createTime.hashCode()
        return result
    }
}